﻿using Data0426.Base.Common;
using Data0426.Base.Dommain;
using Data0426.Base.Infrastructure;
using Data0426.Base.Read.API.Applaction.Command;
using MediatR;

namespace Data0426.Base.Write.API.Applaction.Hander
{
    public class UpdateHander : IRequestHandler<UpdateCommand, ApiResult<int>>
    {
        private readonly IBaseRequest<FormType> FormTypesequest;

        public UpdateHander(IBaseRequest<FormType> formTypesequest)
        {
            FormTypesequest = formTypesequest;
        }

        public Task<ApiResult<int>> Handle(UpdateCommand request, CancellationToken cancellationToken)
        {
            var result=new ApiResult<int>();
            var ifno = FormTypesequest.GetAll().Where(x => x.Id == request.Id).First();
            FormType fo = new FormType();
            fo.Id = request.Id;
            fo.IndescsId=request.IndescsId;
            fo.FormTypeName=request.FormTypeName;
            var entity = FormTypesequest.Update(fo);
            if(entity>0)
            {
                result.data = entity;
                result.code = ApiEnumcode.OK;
                result.meg = "修改成功";
               
            }
            return Task.FromResult(result);

        }
    }
}
